package project.Dao;/*
 *  @Author Mr.long
 *  @QQ 1507468405
 *  @Creat 2021/11/24 - 23:18
 */

import Utils.JDBCTemp;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import project.Domain.Meeting;
import project.Domain.Notice;

import java.util.List;

public class MeetDao {
    private JdbcTemplate template = new JdbcTemplate(JDBCTemp.getDataSource());

    public List<Meeting> queryAll(int id) {
        //根据id查询该用户的上级编号，来查询其可见的通知列表
        String sql = "select * from xm05_meeting_info where publisherID = ?";
        List<Meeting> meetings = template.query(sql, new BeanPropertyRowMapper<Meeting>(Meeting.class), id);
        return meetings;
    }

    public boolean insert(Meeting meeting) {
        String sql = "insert into xm05_meeting_info(publisherID,publisherName,title,content,deliverTime,meetingTime) values(" +
                "?,?,?,?,?,?)";
        int update = template.update(sql, meeting.getPublisherID(),meeting.getPublisherName(), meeting.getTitle(),
                meeting.getContent(),
                meeting.getDeliverTime(),meeting.getMeetingTime());
        return update > 0;
    }

    public boolean delete(int id) {
        String sql = "delete from xm05_meeting_info where id = ?";
        int update = template.update(sql, id);
        return update > 0;
    }

    public boolean update(Meeting meeting) {
        String sql = "update xm05_meeting_info set publisherID=?,title=?,content=?,deliverTime=?,meetingTime=?," +
                "meetingTime=? where" +
                " " +
                "id = ?";
        int update1 = template.update(sql, meeting.getPublisherID(), meeting.getTitle(), meeting.getContent(), meeting.getDeliverTime(),
                meeting.getMeetingTime(),meeting.getMeetingTime(),meeting.getId());
        return update1>0;
    }
}
